#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, L;
    cin >> N >> L;
    
    // Check if L is divisible by 3
    if (L % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    
    long long target = L / 3;
    
    vector<long long> d(N-1);
    for (int i = 0; i < N-1; ++i) {
        cin >> d[i];
    }
    
    // Compute absolute positions
    vector<long long> pos(N);
    pos[0] = 0;
    for (int i = 1; i < N; ++i) {
        pos[i] = (pos[i-1] + d[i-1]) % L;
    }
    
    // Count frequency of each position
    unordered_map<long long, int> freq;
    for (long long p : pos) {
        freq[p]++;
    }
    
    long long count = 0;
    for (long long p : pos) {
        long long p1 = (p + target) % L;
        long long p2 = (p + 2 * target) % L;
        
        // Check if all three positions exist and are distinct
        if (freq.count(p1) && freq.count(p2)) {
            // Add the product of their frequencies
            count += freq[p1] * freq[p2];
        }
    }
    
    // Each triplet is counted 3 times (once for each point), so divide by 3
    cout << count / 3 << endl;
    
    return 0;
}